<template>
	<view>
		<cusSwiperVue :swiperList="swiperList"></cusSwiperVue>
		详情页，您点的房源的id是:{{id}}
		我的id是{{meId}}，跟id为{{houseDetail.personId}}的客服在聊天
		<button @click="goChat">联系客服</button>
		<button @click="doChat">微聊</button>
		
		<image :src="houseDetail.imgUrl"></image>
		<view class="house-title">
			房源名字：{{houseDetail.title}}
			
		</view>
		<view>
			房源价格：{{houseDetail.unitPrice}}
		</view>
		<view>
			房源地址：{{houseDetail.address}}
		</view>
		<button @click="doPay">测试支付</button>
		<button @click="businessPay">真实支付</button>
	</view>
</template>

<script setup>
import { ref } from 'vue';
// 所有uniapp提供的页面级别的生命周期，一定要先引入再使用，从@dcloudio/uni-app引入
import {onLoad} from '@dcloudio/uni-app'
import cusSwiperVue from '../../components/cus-swiper/cus-swiper.vue';
const handleHouse = uniCloud.importObject('handlehouse')
const swiperList = ref([
		{imgUrl: 'http://gips3.baidu.com/it/u=3886271102,3123389489&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960', id: 1},
		{imgUrl: 'http://gips0.baidu.com/it/u=1690853528,2506870245&fm=3028&app=3028&f=JPEG&fmt=auto?w=1024&h=1024', id: 2},
		{imgUrl: 'http://gips3.baidu.com/it/u=1821127123,1149655687&fm=3028&app=3028&f=JPEG&fmt=auto?w=720&h=1280', id: 3},
		{imgUrl: 'http://gips2.baidu.com/it/u=195724436,3554684702&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960', id: 4},
	])
	const id = ref('')
	const meId = ref('bin')
	
	onLoad( (options) => {
		console.log(options)
		id.value = options.id
		getDetail()
	})
	// 跳转到聊天页面的时候一定要确认，谁跟谁聊天，通过页面url的参数来确定聊天双方
	const goChat = () => {
		// uni.navigateTo({
		// 	url: `/pagesA/chat/chat?meId=${meId.value}&toId=${toId.value}`
		// })
		uni.navigateTo({
			url: `/moduleA/talk/talk?meId=${meId.value}&toId=${toId.value}`
		})
	}
	const doChat = () => {
		uni.navigateTo({
			url: `/moduleA/wechat/wechat?meId=${meId.value}&toId=${houseDetail.value.personId}`
		})
	}
	const houseDetail = ref({})
	// 获取房源详情的方法
	const getDetail = async () => {
		const res = await handleHouse.getDetail(id.value)
		console.log(res)
		if(res.data.length>0) {
			houseDetail.value = res.data[0]
		} else {
			uni.$u.toast('未找到对应的详情信息')
		}
	}
	// 支付方法
	const doPay = () => {
		// 应付考试
		uni.requestPayment({
		    provider: 'wxpay',
			timeStamp: String(Date.now()),
			nonceStr: 'A1B2C3D4E5',
			package: 'prepay_id=wx20180101abcdefg',
			signType: 'MD5',
			paySign: '',
			success: function (res) {
				console.log('success:' + JSON.stringify(res));
			},
			fail: function (err) {
				console.log('fail:' + JSON.stringify(err));
			}
		});
	}
	const businessPay = () => {
		// 判断登录
		const token = uni.getStorageSync('token')
		if(!token) {
			uni.navigateTo({
				url: '/pages/authLogin/authLogin'
			})
			return
		}
		uniCloud.callFunction({
			name: 'payorder',
			data: {
				openid: uni.getStorageSync('openid'),
			},
			success(res) {
				console.log(res)
			}
		})
		
	}
</script>

<style>
	       
</style>
